package com.zui.entity.product;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.sun.istack.internal.NotNull;
import com.zui.entity.BaseAssignedIdEntity;

@Entity
@Table(name = "catalog")
public class Catalog extends BaseAssignedIdEntity {
	private static final long serialVersionUID = 1L;

	private String name;
	private String nameEn;
	private Set<CatalogCategory> catalogCategories = new LinkedHashSet<CatalogCategory>();
	@Transient
	public Set<Category> getChildCategories() {
		Iterator<CatalogCategory> it = catalogCategories.iterator();
		Set<Category> children = new LinkedHashSet<Category>();
		while (it.hasNext())
			children.add(it.next().getCategory());
		return children;
	}	
	
	
	/*------------------------------
	 * getters and annotations
	 --------------------------------*/	
	@Column(length = 50) @NotNull
	public String getName() {return name;}
	@Column(length = 50) @NotNull
	public String getNameEn() {return nameEn;}
	@OneToMany(mappedBy = "catalog", fetch = FetchType.LAZY,cascade = {CascadeType.ALL})
	@OrderBy(value = "sequenceNum")
	public Set<CatalogCategory> getCatalogCategories() {
		return catalogCategories;
	}

	/*------------------------------
	 * setters
	 --------------------------------*/
	public void setName(String name) {
		this.name = name;
	}
	public void setNameEn(String nameEn) {
		this.nameEn = nameEn;
	}
	public void setCatalogCategories(Set<CatalogCategory> catalogCategories) {
		this.catalogCategories = catalogCategories;
	}	
}
